package com.greendragon.service.backend.impl; 

import java.util.List;

import com.greendragon.persistence.dao.ICommentDao;
import com.greendragon.persistence.dao.IPageDao;
import com.greendragon.persistence.domain.Page;
import com.greendragon.persistence.domain.PageComment;
import com.greendragon.persistence.enmu.FetchOrderType;
import com.greendragon.persistence.enmu.LockType;
import com.greendragon.persistence.enmu.VerifyType;
import com.greendragon.service.backend.IPageBackendService;

/** 
 * @author wulibin, exceptsky@gmail.com, 2011-11-12 下午03:43:31
 * 
 */
public class PageBackendService extends BaseBackendService<Page> implements IPageBackendService {
	private IPageDao pageDao;
	private ICommentDao<PageComment> commentDao;
	
	@Override
	public void addComment(long pid, PageComment comment) {
		comment.setPage(get(pid));
		commentDao.add(comment);
	}

	@Override
	public long getCommentCount(long pid) {
		return commentDao.getCountOfObj(pid, LockType.UNLOCK, VerifyType.VERIFY);
	}

	@Override
	public List<PageComment> getComments(long pid, int page) {
		return commentDao.getOfObj(pid, pageLength*page, pageLength, LockType.UNLOCK, VerifyType.VERIFY, FetchOrderType.CREATE_DESC);
	}
	
	public void setCommentDao(ICommentDao<PageComment> commentDao) {
		this.commentDao = commentDao;
	}
	
	public void setPageDao(IPageDao pageDao) {
		this.pageDao = pageDao;
		this.setDao(this.pageDao);
	}
}